package com.atguigu.srb.core.controller.admin;


import com.atguigu.common.results.R;
import com.atguigu.srb.core.pojo.entity.UserLoginRecord;
import com.atguigu.srb.core.service.UserLoginRecordService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 用户登录记录表 前端控制器
 * </p>
 *
 * @author Atguigu
 * @since 2022-10-24
 */
@RestController

@RequestMapping("/admin/core/userLoginRecord")
public class AdminUserLoginRecordController {
    @Autowired
    UserLoginRecordService userLoginRecordService;
    //查询会员近20条登录日志： 按照创建时间降序排列
    @ApiOperation("查询会员登录日志")
    @GetMapping("list/{userId}")
    public R listRecords(@PathVariable("userId")String userId){
        List<UserLoginRecord> userLoginRecords = userLoginRecordService.list(new LambdaQueryWrapper<UserLoginRecord>()
                .eq(UserLoginRecord::getUserId, userId)
                .orderByDesc(UserLoginRecord::getCreateTime)
                .last("limit 20"));

        return R.success().data("items" , userLoginRecords);
    }

}

